#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename	:  sendMail
# Version	:  1.0
# Date		:  2022/02/11
# Author	:  Lz
# Email		:  liuzuo@kylinos.com.cn 
# History	:     
# 	           Version 1.0, 2022/02/11
# Function	:  发送邮件服务
# Out		:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

# 测试主题
Title_Env_LTFLIB="安全加固(配置类) - 发送邮件服务"


## TODO : 个性化,初始化
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestInit_LTFLIB(){
	if [ "Z${SendMail_Config_SSRFlag}" == "Z" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "未定义变量 SendMail_Config_SSRFlag"
	elif [ "Z${SendMail_Config_SSRFlag}" != "ZTrue" -a "Z${SendMail_Config_SSRFlag}" != "ZFalse" ];then
		OutputRet_LTFLIB "${ERROR}"	
		TestRetParse_LTFLIB "SendMail_Config_SSRFlag 无效的参数: ${SendMail_Config_SSRFlag}"
	fi

        return $TPASS
}


## TODO : 清理函数
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
TestClean_LTFLIB(){
        return $TPASS
}


## TODO : 测试用例集
#   Out : 0=>TPASS
#         1=>TFAIL
#         2=>TCONF
Testsuite_LTFLIB(){
        testcase_1
        return $TPASS
}


## TODO : 测试用例
testcase_1(){
	local svcnames="postfix sendmail"
	local svcname=""

	for svcname in ${svcnames[@]}
	do
		SvcExist_LTFLIB "isExist" "yes" "${svcname}"
		if [ $? -eq 0 ];then
			# 存在服务
			SvcEnable_LTFLIB "${SendMail_Config_SSRFlag}" "no" "${svcname}"
			TestRetParse_LTFLIB "$svcname 要求自启动状态为 ${SendMail_Config_SSRFlag}" "False"
		
			SvcActive_LTFLIB "${SendMail_Config_SSRFlag}" "no" "${svcname}"
			TestRetParse_LTFLIB "$svcname 要求当前状态为 ${SendMail_Config_SSRFlag}" "False"
		else
			# 服务不存在
		        OutputRet_LTFLIB "${TPASS}"
                	TestRetParse_LTFLIB "${svcname} 服务不存在"
		fi
	done
}


#----------------------------------------------#

source "${LIB_LTFLIB}"
Main_LTFLIB $@
